<?php
class arctypeAction extends CommonAction{
    function index($typeid=0,$p=1,$typealias=""){
        $arctype=array();
        $carctype_M=D('CArctype');
        //获取分类信息并检测
        if(!$typeid || !is_numeric($typeid)){
            if(!empty($typealias)){
                $arctype = $carctype_M->GetTypeByAlias($typealias);
                $typeid = $arctype['id'];
            }else{
                send_http_status("404");//分类不存在，返回404错误
            }
        }else{
            $arctype=$carctype_M->GetTypeById($typeid);
        }
        
        //分类不存在，返回404错误
        if(!$arctype){
            send_http_status("404");
        }
        
        //当前页码检测
        $p = intval($p);
        $p = empty($p)?1:$p;
        
        //每页数量
        $pagesize=empty($arctype['pagesize'])?20:intval($arctype['pagesize']);
        
        //读取文档列表
        $carchive_M=D('CArchive');
        $list=$carchive_M->page($p.",".$pagesize)->GetArcList($typeid,'id|desc');
        //额外的字段
        $arctype['p']=$p;//当前页码
        $arctype['typename']=$arctype['name'];//字段更加友好易读
        $arctype['totalcount']=$carchive_M->where($carchive_M->listMap($typeid))->count("id");//总文章数量
        
        $arctype['listpage']=$carctype_M->GetListPage($typeid,$p,ceil($arctype['totalcount']/$pagesize),$arctype,$arctype['totalcount']);//生成分页链接
        $arctype['position']=$carctype_M->GetPosition($typeid);//位置连接，面包屑导航
        $this->assign("list",$list);
        $this->assign("arctype",$arctype);
        $this->_display("list_arctype");
    }
}
